package com.shop.web.shiro.matcher;

import com.shop.web.shiro.token.BaseUsernamePasswordToken;
import com.shop.web.shiro.token.LoginTypeEnum;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;

public class BaseCredentialsMatch extends HashedCredentialsMatcher {

    public BaseCredentialsMatch () {
        super();
    }

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        //增加免密登录功能，使用自定义token
        BaseUsernamePasswordToken usertoken = (BaseUsernamePasswordToken) token;

        //免密登录,不验证密码
        if (LoginTypeEnum.NO_PASSWORD.equals(usertoken.getLoginTypeEnum())){
            return true;
        }

        return super.doCredentialsMatch(token, info);
    }

}
